<?php

namespace app\model;

use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class VoiceChatUser extends Base
{

    protected $table = "voice_chat_user";


    protected $connection;


    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        $this->connection = config('database.connections.biqi_game.database');
    }


    public function userData(): Attribute
    {

        return Attribute::make(
            get: fn(string $value) => json_decode($value, true),
            set: fn(array $value) => json_encode($value),
        );

    }


    public function UserBind(): BelongsTo
    {

        return $this->belongsTo(User::class, 'user', 'ulid')->where('state', 1);

    }

}